import {
    getInfoByProject,
    // 基桩检测统计获取项目名称
    getProjectIdAndName,
    // 基桩检测统计获取施工单位名称
    getCompanyIdAndName,
    // getCheckTypeByUserList
} from "@/api/request.js";

import actions from "@/actions";
import TableLyout from '@/components/commonPublic/tableLyout.vue'
import TableData from "@/components/commonPublic/el-table"; //主页面列表
import formJs from "./regexDetail.js"; //新增弹框配置项
import publicForm from "@/components/PCManage/fromCom.vue"; //弹框form

export default {
    name: "section",
    data() {
        return {
            names: "section",
            projectsObj: [], //项目名
            tendersObj: [],
            falgId: null,
            editLoading: false,
            queryCriteriaData: {}, //分页
            searchObj: formJs.searchObj, //搜索条件
            table_config: formJs.table_config, //列表
            getList: {
                fprojectid: "",
                fCompanyid: null, //机构id
                fUserid: null, //当前登录用户id
                sublevel: "1", //查看下级  1是0否
                page: 1, //页码
                pageSize: 15, //每页条数
                keyWord: "", // 选择状态
            },




            lr_look: null,
            projectList: [],
            Checktype: [{
                    fItemName: "==请选择==",
                    fItemValue: "==请选择==",
                },
                {
                    fItemName: "未开始",
                    fItemValue: "未开始",
                },
                {
                    fItemName: "检测中",
                    fItemValue: "检测中",
                },
                {
                    fItemName: "已结束",
                    fItemValue: "已结束",
                },
            ], //检测状态：- 根据当前登录用户获取检测类型
            getList: {
                fDepartmentid: "", // 项目id
                fCompanyid: "", // 施工单位id
                keyWord: "", // 检测状态
                modelType: "1", // 0-按建设项目   1-按施工单位   2-按工程项目
                page: 1,
                pageSize: 20,
                fUserid: "",
                companyid: "",
            },
            navigatepageNums: null, //是否显示分页
            queryCriteriaData: {},
            formData: {},
            loading: false,
            tableData: [], //列表数据
        };
    },
    mounted() {

        // this.userInfo = JSON.parse(sessionStorage.getItem("GxEmbedded_userInfo"));
        // this.getList.fUserid = this.userInfo.userId;
        // this.getList.companyid = this.userInfo.companyId;
        // this.yj_searchForm(this.getList);
        // // 项目名称数据
        // this.getProjectIdAndName();
        actions.onGlobalStateChange((state, prev) => {
            this.userInfo = prev.currentUser
        }, true);

        this.getList.fUserid = this.userInfo.id;
        this.getList.fCompanyid = this.userInfo.companyId;
        if (JSON.parse(sessionStorage.getItem("GxEmbedded_pcManage_getList"))) {
            var getListStorage = JSON.parse(sessionStorage.getItem("GxEmbedded_pcManage_getList"));
            this.getList = getListStorage
            if (getListStorage.fprojectid != "") {}
            this.yj_searchForm(this.getList)

        } else {
            this.yj_searchForm(this.getList)
        }
    },
    components: {
        TableLyout,
        TableData,
        publicForm
    },
    methods: {
        reset(e) {
            this.getList = this.$options.data.call(this).getList
            this.getList.fprojectid = e
        },
        // 选择项目名称
        selectCompany(e) {
            this.companyName = e.F_ProjectName;
            this.getList.fDepartmentid = e.F_ProjectId;
            this.projectName = "";
            this.getList.fCompanyid = "";
            // 调用施工单位数据
            this.getCompanyIdAndName(e.F_ProjectId);

            // this.yj_searchForm(this.getList);
        },
        // 选择施工单位
        selectProject(e) {
            console.log(e);
            this.projectName = e.F_CompanyName;
            this.getList.fCompanyid = e.F_CompanyId;
            // this.yj_searchForm(this.getList);
        },
        // 项目名称数据
        getProjectIdAndName() {
            getProjectIdAndName({})
                .then((res) => {
                    if (res.errcode == 0) {
                        var arr = [{
                            F_ProjectId: "",
                            F_ProjectName: "请选择",
                        }, ];
                        this.companyList = arr.concat(res.data.projectList);
                    } else {
                  
                        this.$message.error({
                            content: "项目名称"+ res.msg,
                            duration: 1000
                        })
                        return false;
                    }
                })
                .catch(() => {
                    console.log("项目名称获取失败");
                    return false;
                });
        },
        // 施工单位数据来源
        getCompanyIdAndName(id) {
            getCompanyIdAndName({
                    projectId: id
                })
                .then((res) => {
                    if (res.errcode == 0) {
                        this.projectList = res.data.companyList;
                    } else {
                        this.$message.error({
                            content: "施工单位"+ res.msg,
                            duration: 1000
                        })
                        return false;
                    }
                })
                .catch(() => {
                    console.log("施工单位获取失败");
                    return false;
                });
        },

        // 点击当前行变色
        rowChange(val) {
            this.currentRow = val;
        },

        // 获取列表数据
        yj_searchForm(data) {
            this.loading = true;
            var that = this;
            window.sessionStorage.setItem(
                "GxEmbedded_pcManage_getList",
                JSON.stringify(data)
            );
            var id;
            if(data.fCompanyid!=''){
              id=data.fCompanyid
            }else {
              id=data.fprojectid
            }
            var obj = {
                fDepartmentid: data.fprojectid,
                fCompanyid: id, //机构id
                fUserid: data.fUserid, //当前登录用户id
                // sublevel: "1", //查看下级  1是0否
                page: data.page, //页码
                pageSize: data.pageSize, //每页条数
                keyWord: data.keyWord, // 选择状态
                modelType: "1", // 0-按建设项目   1-按施工单位   2-按工程项目

                companyid: this.userInfo.companyId,


            }

            getInfoByProject(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;

                        this.queryCriteriaData = res.data.pageInfo;
                        this.navigatepageNums =
                            this.queryCriteriaData.navigatepageNums.length;
                    } else {
                        this.loading = false;
                    
                        this.$message.error({
                            content: "列表数据"+ res.msg,
                            duration: 1000
                        })
                    }
                })
                .catch((err) => {
                    console.log("列表接口", err);
                    this.loading = false;
                });
        },
    },
};